//author:kakake
var Model = /** @class */ (function () {
    function Model() {
    }
    return Model;
}());

//author:kakake
var Common = /** @class */ (function () {
    function Common() {
    }
    return Common;
}());

//author:kakake
var tsgbdrugDao = /** @class */ (function () {
    function tsgbdrugDao() {
        this.dbConn = TSLobsterAPI.Program.GetDbConn();
    }
    return tsgbdrugDao;
}());

//author:kakake
var tsgbdrugService = /** @class */ (function () {
    function tsgbdrugService() {
    }
    return tsgbdrugService;
}());

//author:kakake
var tsgbdrugController = /** @class */ (function () {
    function tsgbdrugController() {
        this.data = {
            dbConn: TSLobsterAPI.Program.GetDbConn()
        };
    }
    //获取药理分类
    tsgbdrugController.prototype.gettree = function () {
        var _this = this;
        var strsql = "SELECT PharmID id,PharmName nodeName,parentId FROM DG_GB_Pharmacology";
        var list = TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql);
        var _root = TSLobsterAPI.Utils.findlist(list, 'parentId', '-1'); //根节点
        var tree = [];
        var lv = 1;
        _root.forEach(function (i) {
            var node = {};
            node["id"] = i['id'];
            node["name"] = i['nodeName'];
            node["title"] = i['nodeName'];
            node["parentid"] = i['parentId'];
            node["spread"] = true;
            node["href"] = "";
            node["selected"] = false;
            node["disabled"] = false;
            node["level"] = 1;
            node["children"] = _this.bulidtree(list, i['id'], lv + 1);
            tree.push(node);
        });
        return tree;
    };
    //绑定树
    tsgbdrugController.prototype.bulidtree = function (List, pid, lv) {
        var _this = this;
        var _childlist = TSLobsterAPI.Utils.findlist(List, 'parentId', pid);
        var treelist = [];
        _childlist.forEach(function (i) {
            var node = {};
            node["id"] = i['id'];
            node["name"] = i['nodeName'];
            node["title"] = i['nodeName'];
            node["parentid"] = i['parentId'];
            node["spread"] = true;
            node["href"] = "";
            node["selected"] = false;
            node["disabled"] = false;
            node["level"] = lv;
            node["children"] = _this.bulidtree(List, i['id'], lv + 1);
            treelist.push(node);
        });
        return treelist;
    };
    //获取基药数据
    tsgbdrugController.prototype.getDrugdata = function () {
        var cid = TSLobsterAPI.Program.RequestQuery("cid", "");
        var lv = TSLobsterAPI.Program.RequestQuery("lv", "");
        var exactQuery = TSLobsterAPI.Program.RequestQuery("exactQuery", "");
        var drugName = TSLobsterAPI.Program.RequestQuery("drugName", "");
        var dosagesName = TSLobsterAPI.Program.RequestQuery("dosagesName", "");
        var pageInfo = {
            key: "BasicDrugID",
            page: TSLobsterAPI.Program.RequestQuery('page', 0),
            perPage: TSLobsterAPI.Program.RequestQuery('limit', 10),
            totalRecord: 0,
            totalPage: 0
        };
        var strsql = "";
        strsql = "SELECT BasicDrugID,BasicDrugName,DrugName,Spec,b.DosageName Dosage, \
        (case IsRecipe when 0 then '否' when 1 then '是'  end) IsRecipe, \
        (case Class when 1 then '化学药品和生物制药' when 2 then '中成药' when 3 then '中草药' end) Class \
        FROM DG_GB_SpecDic a INNER JOIN DG_GB_DosageDic b on a.DosageID=b.DosageID and a.WorkID=b.WorkID where 1=1 ";
        if (parseInt(lv) == 1) {
            strsql = strsql + " and a.TypeID in (select PharmID from  DG_GB_Pharmacology  where DelFlag=0 and ParentID=@cid)";
        }
        else if (parseInt(lv) == 2) {
            strsql = strsql + " and a.TypeID = @cid";
        }
        else if (parseInt(lv) == 3) {
            strsql = strsql + " and a.CTypeID = @cid";
        }
        else if (parseInt(lv) == 4) {
            strsql = strsql + " and a.PharmID = @cid";
        }
        if (drugName != "") {
            if (exactQuery == "true") {
                strsql = strsql + " and DrugName = @drugName";
            }
            else {
                strsql = strsql + " and DrugName like @_drugName ";
            }
        }
        var dbparams = {
            cid: cid,
            drugName: drugName,
            _drugName: '%' + drugName + '%'
        };
        //获取分页Sql和条数
        var _list = TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, dbparams, pageInfo);
        var List = [];
        _list.forEach(function (result) {
            var item = {};
            item["药品ID"] = result["BasicDrugID"];
            item["品种名称"] = result["BasicDrugName"];
            item["药品名称"] = result["DrugName"];
            item["规格"] = result["Spec"];
            item["剂型"] = result["Dosage"];
            item["类型"] = result["Class"];
            item["处方资质"] = result["IsRecipe"];
            List.push(item);
        });
        return { List: List, count: pageInfo.totalRecord };
    };
    return tsgbdrugController;
}());

